<template>
    <div class="tip-box" :style="getTime">{{msg}}</div>
</template>

<script>
export default {
    data: function() {
        return {
            msg: "我是一个弹窗",
            time: 3
        };
    },
    computed: {
        getTime() {
            return "animation-duration:" + this.time + "s";
        }
    },
    mounted() {
        document.body.appendChild(this.$el);
        setTimeout(() => {
            document.body.removeChild(this.$el);
            this.$destroy();
        }, this.time * 1000);
    }
};
</script>

<style>
.tip-box {
    transform: translate(-50%, -100%);
    background-color: rgba(0, 0, 0, 0.6);
    color: white;
    padding: 10px 14px;
    position: fixed;
    top: 0px;
    left: 50%;
    border-radius: 6px;
    animation: tipFade 1;
    /* animation-duration: ; */
}

@keyframes tipFade {
    0% {
        transform: translate(-50%, -100%);
    }

    15% {
        transform: translate(-50%, 20px);
    }

    85% {
        transform: translate(-50%, 20px);
    }

    100% {
        transform: translate(-50%, -100%);
    }
}
</style>